"use strict";

const Controller = require('egg').Controller;

class StuController extends Controller {
    async addStu() {
        const { ctx } = this;
        const params = {
            name: '12312',
            age: 20
        };
        const result = await ctx.service.stu.addStu(params);
        if (result.affectedRows === 1) {
            ctx.body = "success";
        }
    }
    async getStu() {
        const { ctx } = this;
        const result = await ctx.service.stu.getStu();
        ctx.body = JSON.stringify(result);
        // const result = await ctx.service.stu.getStu();
        // ctx.body = result;
    }
    async updateStu() {
        const { ctx } = this;
        const params = {
            id: 1,
            name: '李四',
            age: 21
        };
        const result = await ctx.service.stu.updateStu(params);
        console.log(result.affectedRows);

        if (result.affectedRows === 1) {
            ctx.body = "success";
        }
    }
    async delStu() {
        const { ctx } = this;
        const params = {
            id: 1
        };
        const result = await ctx.service.stu.delStu(params);
        if (result.affectedRows === 1) {
            ctx.body = "success";
        }
    }
}

module.exports = StuController; 